<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no"/>
    <title>打印控制面板</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        h1, h2 {
            color: #333;
        }
        .section {
            margin-bottom: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        button {
            padding: 5px 10px;
            margin: 5px;
            cursor: pointer;
        }
        input, select {
            padding: 5px;
            margin: 5px;
        }
        .result {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ccc;
            background-color: #f9f9f9;
            min-height: 100px;
        }
    </style>
</head>
<body>
    <h1>打印机控制面板</h1>
    
    <div class="result" id="result">
        <p>操作结果将显示在这里...</p>
    </div>
    
    <div class="section">
        <h2>基本控制</h2>
        <button onclick="callApi('GET', '/api/print/init')">初始化打印机</button>
        <button onclick="callApi('GET', '/api/print/free')">释放资源</button>
        <button onclick="callApi('GET', '/api/print/initPrint')">清除缓存</button>
        <button onclick="callApi('GET', '/api/print/feedToNext')">走纸</button>
        <button onclick="callApi('GET', '/api/print/blackLabelOn')">开启黑标检测</button>
        <button onclick="callApi('GET', '/api/print/blackLabelOff')">关闭黑标检测</button>
        <button onclick="callApi('GET', '/api/print/restoreDefault')">恢复默认设置</button>
    </div>
    
    <div class="section">
        <h2>信息查询</h2>
        <button onclick="callApi('GET', '/api/print/getVersion')">获取版本</button>
        <button onclick="callApi('GET', '/api/print/getFontVersion')">获取字体版本</button>
        <button onclick="callApi('GET', '/api/print/getBaudRate')">获取波特率</button>
    </div>
    
    <div class="section">
        <h2>打印文本</h2>
        <div>
            <textarea id="textContent" rows="4" style="width: 90%" placeholder="请输入要打印的文本内容"></textarea>
        </div>
        <div>
            <label>字符集：</label>
            <input type="text" id="charsetName" value="gbk">
        </div>
        <button onclick="printText()">打印文本</button>
    </div>
    
    <div class="section">
        <h2>打印图片</h2>
        <div>
            <textarea id="imageContent" rows="4" style="width: 90%" placeholder="请输入Base64编码的图片内容"></textarea>
        </div>
        <div>
            <label>宽度：</label>
            <input type="number" id="imageWidth" value="320">
            <label>高度：</label>
            <input type="number" id="imageHeight" value="240">
            <label>间隔：</label>
            <input type="number" id="imageInterval" value="100">
        </div>
        <button onclick="printImage()">打印图片</button>
    </div>
    
    <div class="section">
        <h2>打印条形码</h2>
        <div>
            <input type="text" id="barcodeContent" style="width: 90%" placeholder="请输入条形码内容">
            123456789
        </div>
        <div>
            <label>条形码类型：</label>
            <input type="text" id="barcodeType" value="UPC_A">
        </div>
        <button onclick="printBarcode()">打印条形码</button>
    </div>
    
    <div class="section">
        <p>下面所有的设置均按照 SDK开发文档-打印机 来</p>
        <h2>打印设置</h2>
        <div>
            <label>打印速度：</label>
            <input type="number" id="printSpeed"  value="100">
            <button onclick="setPrintSpeed()">设置</button>
        </div>
        <div>
            <label>打印浓度(1-9)：</label>
            <input type="number" id="printChroma" min="1" max="9" value="5">
            <button onclick="setPrintChroma()">设置</button>
        </div>
        <div>
            <label>对齐模式(0左/1中/2右)：</label>
            <input type="number" id="alignmentMode" min="0" max="2" value="0">
            <button onclick="setPrintAlignment()">设置</button>
        </div>
        <div>
            <label>行距(0-255)：</label>
            <input type="number" id="rowSpacing" min="0" max="255" value="30">
            <button onclick="setRowSpacing()">设置</button>
        </div>
        <div>
            <label>左边距 nl：</label>
            <input type="number" id="marginNl" min="0" max="255" value="0">
            <label>nh：</label>
            <input type="number" id="marginNh" min="0" max="255" value="0">
            <button onclick="setLeftMargin()">设置</button>
        </div>
        <div>
            <label>走纸行数 类型：</label>
            <input type="number" id="feedType" min="0" max="1" value="0">
            <label>行数：</label>
            <input type="number" id="feedN" min="0" max="255" value="5">
            <button onclick="setFeedRow()">设置</button>
        </div>
        <div>
            <label>GSP模式 x：</label>
            <input type="number" id="gspX" min="0" max="255" value="0">
            <label>y：</label>
            <input type="number" id="gspY" min="0" max="255" value="0">
            <button onclick="setGSPMode()">设置</button>
        </div>
    </div>
    
    <div class="section">
        <p>下面所有的设置均按照 SDK开发文档-打印机 来</p>
        <h2>条码设置</h2>
        <div>
            <label>条码高度(1-255)：</label>
            <input type="number" id="barcodeHeight" min="1" max="255" value="60">
            <button onclick="setBarcodeHeight()">设置</button>
        </div>
        <div>
            <label>条码宽度(2-6)：</label>
            <input type="number" id="barcodeWidth" min="2" max="6" value="3">
            <button onclick="setBarcodeWidth()">设置</button>
        </div>
        <div>
            <label>条码HRI位置(0-3)：</label>
            <input type="number" id="barcodeHRI" min="0" max="3" value="2">
            <button onclick="setBarcodeHRI()">设置</button>
        </div>
    </div>
    
    <div class="section">
        <p>下面所有的设置均按照 SDK开发文档-打印机 来</p>
        <h2>字体设置</h2>
        <div>
            <label>下划线模式(0-2)：</label>
            <input type="number" id="underlineMode" min="0" max="2" value="0">
            <button onclick="setUnderlineMode()">设置</button>
        </div>
        <div>
            <label>粗体模式(0-1)：</label>
            <input type="number" id="boldMode" min="0" max="1" value="0">
            <button onclick="setBoldMode()">设置</button>
        </div>
        <div>
            <label>字体尺寸(0-7)：</label>
            <input type="number" id="fontDimension" min="0" max="7" value="0">
            <button onclick="setFontDimension()">设置</button>
        </div>
    </div>
    
    <div class="section">
        <p>下面所有的设置均按照 SDK开发文档-打印机 来</p>
        <h2>出厂设置</h2>
        <div>
            <label>恢复出厂设置(0-9)：</label>
            <input type="number" id="restoreFactoryN" min="0" max="9" value="9">
            <button onclick="restoreFactory()">恢复出厂设置</button>
        </div>
    </div>

    <script>
        function callApi(method, url, data = null) {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = '<p>请求中，请稍候...</p>';
            
            const options = {
                method: method,
                headers: {
                    'Content-Type': 'application/json'
                }
            };
            
            if (data) {
                options.body = JSON.stringify(data);
            }
            
            fetch(url, options)
                .then(response => response.json())
                .then(data => {
                    resultDiv.innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
                })
                .catch(error => {
                    resultDiv.innerHTML = '<p style="color: red;">错误: ' + error.message + '</p>';
                });
        }
        
        function sendData() {
            const content = document.getElementById('textContent').value;
            callApi('POST', '/api/print/sendData', { content: content });
        }
        
        function printText() {
            const content = document.getElementById('textContent').value;
            const charsetName = document.getElementById('charsetName').value;
            callApi('POST', '/api/print/printText', { 
                content: content,
                charsetName: charsetName
            });
            setFeedRow();
        }
        
        function printImage() {
            const content = document.getElementById('imageContent').value;
            const width = parseInt(document.getElementById('imageWidth').value);
            const height = parseInt(document.getElementById('imageHeight').value);
            const interval = parseInt(document.getElementById('imageInterval').value);
            callApi('POST', '/api/print/printImage', { 
                content: content, //base64编码图片
                width: width,
                height: height,
                interval: interval
            });
        }
        
        function print() {
            const content = document.getElementById('imageContent').value;
            const interval = parseInt(document.getElementById('imageInterval').value);
            callApi('POST', '/api/print/print', { 
                content: content,
                interval: interval
            });
        }
        
        function printBarcode() {
            const content = document.getElementById('barcodeContent').value;
            const barcodeType = document.getElementById('barcodeType').value;
            callApi('POST', '/api/print/printBarcode', {
                content: content,
                barcodeType: barcodeType
            });
            setFeedRow();
        }
        
        function setPrintSpeed() {
            const speed = parseInt(document.getElementById('printSpeed').value);
            callApi('POST', `/api/print/setPrintSpeed?speed=${speed}`);
        }
        
        function setPrintChroma() {
            const chroma = parseInt(document.getElementById('printChroma').value);
            callApi('POST', `/api/print/setPrintChromaLevel?chroma=${chroma}`);
        }
        
        function setPrintAlignment() {
            const mode = parseInt(document.getElementById('alignmentMode').value);
            callApi('POST', `/api/print/setPrintAlignmentMode?mode=${mode}`);
        }
        
        function setRowSpacing() {
            const spacing = parseInt(document.getElementById('rowSpacing').value);
            callApi('POST', `/api/print/setPrintRowSpacing?spacing=${spacing}`);
        }
        
        function setLeftMargin() {
            const nl = parseInt(document.getElementById('marginNl').value);
            const nh = parseInt(document.getElementById('marginNh').value);
            callApi('POST', `/api/print/setPrintLeftMargin?nl=${nl}&nh=${nh}`);
        }
        
        function setFeedRow() {
            const type = parseInt(document.getElementById('feedType').value);
            const n = parseInt(document.getElementById('feedN').value);
            callApi('POST', `/api/print/setFeedRow?type=${type}&n=${n}`);
        }
        
        function setGSPMode() {
            const x = parseInt(document.getElementById('gspX').value);
            const y = parseInt(document.getElementById('gspY').value);
            callApi('POST', `/api/print/setGSPMode?x=${x}&y=${y}`);
        }
        
        function setBarcodeHeight() {
            const height = parseInt(document.getElementById('barcodeHeight').value);
            callApi('POST', `/api/print/setBarcodeHeight?height=${height}`);
        }
        
        function setBarcodeWidth() {
            const width = parseInt(document.getElementById('barcodeWidth').value);
            callApi('POST', `/api/print/setBarcodeWidth?width=${width}`);
        }
        
        function setBarcodeHRI() {
            const position = parseInt(document.getElementById('barcodeHRI').value);
            callApi('POST', `/api/print/setBarcodeHRI?position=${position}`);
        }
        
        function setUnderlineMode() {
            const n = parseInt(document.getElementById('underlineMode').value);
            callApi('POST', `/api/print/setUnderlineMode?n=${n}`);
        }
        
        function setBoldMode() {
            const n = parseInt(document.getElementById('boldMode').value);
            callApi('POST', `/api/print/setBoldMode?n=${n}`);
        }
        
        function setFontDimension() {
            const n = parseInt(document.getElementById('fontDimension').value);
            callApi('POST', `/api/print/setFontDimension?n=${n}`);
        }
        
        function restoreFactory() {
            const n = parseInt(document.getElementById('restoreFactoryN').value);
            callApi('POST', `/api/print/restoreFactory?n=${n}`);
        }
    </script>
</body>
</html> 